Trò chơi Tic-Tac-Toe, game đánh caro full source code
53.595 lượt xem;
- OnJoinInstantiate.cs
- DemoChangeOwner /
- Demos /
- Photon Unity Networking /
- Assets /
- project /
1 using UnityEngine;
2 using System.Collections;
3
4
5 public class OnJoinInstantiate : MonoBehaviour
6 {
7 public Transform ObjectToInstantiate;
8
9 public bool InstantiateSceneObjects = false;
10
11 public GameObject newObj; // not used but to show that you get the GO as return
12
13 public void OnJoinedRoom()
14 {
15 Vector3 pos = Vector3.zero;
16 pos.x += PhotonNetwork.player.ID;
17
18 if (!InstantiateSceneObjects)
19 {
20
21 newObj = PhotonNetwork.Instantiate(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
22
23
24 // anything you do with newObj locally is not reflected on the other clients.
25 // you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
26 }
27 else
28 {
29 newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
30 //PhotonView pv = newObj.GetComponent<PhotonView>() as PhotonView;
31 //Debug.Log(pv.ownerId + " " + pv.viewID);
32 }
33 }
34 }
2 using System.Collections;
3
4
5 public class OnJoinInstantiate : MonoBehaviour
6 {
7 public Transform ObjectToInstantiate;
8
9 public bool InstantiateSceneObjects = false;
10
11 public GameObject newObj; // not used but to show that you get the GO as return
12
13 public void OnJoinedRoom()
14 {
15 Vector3 pos = Vector3.zero;
16 pos.x += PhotonNetwork.player.ID;
17
18 if (!InstantiateSceneObjects)
19 {
20
21 newObj = PhotonNetwork.Instantiate(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
22
23
24 // anything you do with newObj locally is not reflected on the other clients.
25 // you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
26 }
27 else
28 {
29 newObj = PhotonNetwork.InstantiateSceneObject(ObjectToInstantiate.name, pos, Quaternion.identity, 0, null);
30 //PhotonView pv = newObj.GetComponent<PhotonView>() as PhotonView;
31 //Debug.Log(pv.ownerId + " " + pv.viewID);
32 }
33 }
34 }
public GameObject newObj; not used but to show that you get the GO as return
anything you do with newObj locally is not reflected on the other clients.
you can add a script to the Prefab to do some instantiation in Awake() and you can call RPCs on newObj now.
PhotonView pv = newObj.GetComponent
Debug.Log(pv.ownerId + " " + pv.viewID);